package interviewQuestions;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

// 根据权重排序  需要实现Comparable接口
public class LetterRGB implements Comparable{
    public static HashMap<Character,Integer> hm = new HashMap<Character,Integer>(){{
        put('R',0);
        put('G',0);
        put('B',0);
    }};

    // 记录字母
    public Character letter;
    // 字母的权重
    public int weight;

    public LetterRGB(Character letter,int weight){
        this.letter = letter;
        this.weight = weight;
    }

    // 通过HashMap记录字母出现的次数然后打印
    public static void resolve1(){
        String str = null;
        Scanner input = new Scanner(System.in);
        str = input.nextLine();
        if(str == null || str.length() == 0){
            System.out.println("没有数据！");
            return;
        }
        for(char c : str.toCharArray()){
            if(c == 'R'){
                hm.put('R',hm.get('R')+1);
            }else if(c == 'G'){
                hm.put('G',hm.get('G')+1);
            }else if(c == 'B'){
                hm.put('B',hm.get('B')+1);
            }
        }

        for (int i = 0; i < hm.get('R'); i++) {
            System.out.print('R');
        }

        for (int i = 0; i < hm.get('B'); i++) {
            System.out.print('B');
        }

        for (int i = 0; i < hm.get('G'); i++) {
            System.out.print('G');
        }
    }


    public static void main(String[] args) {
        // 权重排序
        Scanner input = new Scanner(System.in);
        String s = null;
        s = input.nextLine();
        LetterRGB[] ls = new LetterRGB[s.length()];
        int i = 0;
        for(char c : s.toCharArray()){
            if(c == 'R')
                ls[i++] = new LetterRGB(c,0);
            else if (c == 'B')
                ls[i++] = new LetterRGB(c,1);
            else if (c == 'G')
                ls[i++] = new LetterRGB(c,2);
        }
        Arrays.sort(ls);
        for (LetterRGB l : ls){
            System.out.print(l.letter);
        }
    }

    @Override
    public int compareTo(Object o) {
        if(o instanceof LetterRGB){
            LetterRGB letterRGB = (LetterRGB) o;
            if(this.weight > letterRGB.weight){
                return 1;
            } else if(this.weight < letterRGB.weight){
                return -1;
            } else{
                return 0;
            }
        }
        throw new RuntimeException("not instanceof LetterRGB");
    }
}
